//
//  PhoneCall.swift
//  Extend
//
//  Created by 郑浩 on 2017/10/27.
//  Copyright © 2017年 敬信. All rights reserved.
//

import UIKit
import CoreTelephony

typealias blk = () -> ();

public class PhoneCall: NSObject {
    public static let share = PhoneCall()
    private override init() {}
    
    var callCenter = CTCallCenter()
    
    public func setCallHandle(disconnected: @escaping () -> (),
                              connected: @escaping () -> (),
                              incoming: @escaping () -> (),
                              dialing: @escaping () -> ()) {
        callCenter.callEventHandler = {(_ call: CTCall) -> Void in
                if (call.callState == CTCallStateDisconnected) {
                    disconnected()
                }
                else if (call.callState == CTCallStateConnected) {
                    connected()
                }
                else if (call.callState == CTCallStateIncoming) {
                    incoming()
                }
                else if (call.callState == CTCallStateDialing) {
                    dialing()
                }
                else {
                    
                }
        }
    }
}


